package com.topgay.controller.chatting;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.view.InternalResourceView;

import com.topgay.domain.TestChatting;
import com.topgay.service.chatting.TestChattingService;

@Controller
@RequestMapping("/chatting/")
public class TestChattingController {
	
	@Autowired
	private TestChattingService service;
	
	@RequestMapping("chattingResultIndex.do")
	public String showResultIndex(){		
		System.out.println("show result");
		return "body/chatting/chatting_test.jsp";
	}
	
	@RequestMapping("chattingIndex.do")
	public String showIndex(){
		return "body/chatting/chatting_test.jsp";
	}
	
	@RequestMapping("send.do")
	public InternalResourceView sendMessage(String fromId, String toId, String message){
		service.sendMessage(fromId, toId ,message);		
		InternalResourceView view = new InternalResourceView("/chatting/chattingResultIndex.do");
		return view;
	}
	
	@RequestMapping("get.do")
	public String getMessage(String friendId, ModelMap map){
		
		List<TestChatting> m_list = service.selectMessage(friendId);
		map.addAttribute("list", m_list);
		
		return "jsonView";
	}
	
	
}
